﻿@{
    ViewBag.Title = "Details";
}
@using SAD_SiS.Models;
@model V_Product
<div class="span2" style="margin-top: 10px">
    <a class="fancybox" href="@Url.Content("~/Content/ProductPic/" + @Model.pic)" data-fancybox-group="gallery">
        <img src="@Url.Content("~/Content/ProductPic/" + @Model.pic)" width="160px" /></a>
</div>
<div id="book-info-2" class="span6" style="margin-top: 10px">
    <p class='book-name main-green-color'>
        @Model.Name
    </p>
    <hr />
    <div id="rating-div">
        <table>
            <tr>
                <td>
                    <strong>Đánh giá: </strong>
                </td>
                <td>
                    <div id="rate" class="rating @(ViewBag.Rate ? "" : "jDisabled")" data-average="@Model.AveScore" data-id="@Model.ProductID">
                    </div>
                    (@Model.AveScore/5) <i>@Model.NumOfRate lượt đánh giá </i>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <p id="pRatingMessage">@ViewBag.RateMess</p>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <p class="price">
                        <strong>Giá:</strong> <span class="label lblSuccess">@Model.SellPrice.000 đ</span>
                        <span class="fullprice">@Model.Price
                            .000đ</span>
                    </p>
                </td>
            </tr>
        </table>
        <hr />
        <table>
            @{
                SADEntities dbContext = new SADEntities();
                var singleDetails = (from d in dbContext.ProductDetails.Include("PropertyType") where d.ProductID == Model.ProductID select d).ToList();
                var details = (from d in dbContext.PropertyTypes where d.CateID == Model.CateID && d.IsSelect == true select d).ToList();
                foreach (var item in singleDetails)
                {
                    if (item.PropertyType.IsSelect == false)
                    {
                <tr>
                    <td>
                        <b>@item.PropertyType.PropertyName :</b>
                    </td>
                    <td>
                        @item.Value
                    </td>
                </tr>
                    }
                }
            }
            <form id='cart-form' class="form-inline">
            @{
                foreach (var item in details)
                {
                    var combo = (from d in dbContext.ProductDetails where d.PropertyTypeID == item.TypeID && d.ProductID == Model.ProductID select d).ToList();
                <tr>
                    <td>
                        <b>@item.PropertyName :</b>
                    </td>
                    <td>
                        <select name="slt-@item.TypeID">
                            @foreach (var c in combo)
                            {
                                <option value="@c.DetailID">@c.Value</option>    
                            }
                        </select>
                    </td>
                </tr>
                }
            }
            <tr>
                <td>
                    <strong>Số lượng :</strong>
                </td>
                <td>
                    <input type="text" id="quantity" name="quantity" class="input-mini mar-right30" value="1" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" class="btn btn-primary" value="Cho vào giỏ hàng" />
                    <input type="hidden" value="@Model.ProductID" id="pid" name="pid" />
                </td>
            </tr>
            </form>
        </table>
    </div>
</div>
<div class="span3" style="margin-top: 10px; border: 1px solid blue; padding: 10px">
    @{
        var shop = (from s in dbContext.Shops where s.ShopID == @Model.ShopID select s).Single();
    }
    <h3>
        <a href="@Url.Action("Views", "ShopHome", new { id = @shop.LinkName }, null)">@shop.ShopName</a>
    </h3>
    <a href="@Url.Action("Views", "ShopHome", new { id = @shop.LinkName }, null)">
        <img src="@Url.Content("~/Content/ShopPic/" + @shop.Logo)" /></a>
    <p style="margin-top: 10px">
        <i>@shop.Slogan</i></p>
    <h4>
        Thông tin shop
    </h4>
    <p>
        Địa chỉ : @shop.Address</p>
    <p>
        Điện thoại : @shop.Phone</p>
</div>
<script type="text/javascript">

    $(document).ready(function () {
        $(".fancybox").fancybox();
        $(".rating").jRating({
            length: 5,
            rateMax: 5,
            type: 'big'
        });
    });
        $('#cart-form').submit(function () {
        var f = $('#cart-form').serialize();
        $.post("@Url.Action("AddToCart", "Cart")",
           f,
            function(data,status,xhr){
                if(data.Success){
                    $().toastmessage('showSuccessToast', "Đã thêm vào giỏ hàng...");
                    $('#cartregion').load("@Url.Action("GetCartButton", "Cart")");        
                }
                else{
                    $().toastmessage('showWarningToast', "Đã thêm vào giỏ hàng...");    
                }
            });
        return false;
    });
     function demo(id, score) {
            $.post("@Url.Action("Rating", "Product")",
            {
                productID: id,
                score: score
            },
            function(data,status,xhr){
                $('#pRatingMessage').html(data.Message);
            });          
     }
    
</script>
@if (false)
{  
    <script src="/Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript">

    </script> 
}
